﻿using System;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System.Collections.Generic;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.ImportProvince
{
        internal class Program
        {
                private static void Main(string[] args)
                {
                        Dictionary<string, List<string>> provinces = new Dictionary<string, List<string>>();

                        using (FileStream fs = File.OpenRead("全国省市地邮编信息.xls"))
                        {
                                var wk = new HSSFWorkbook(fs);
                                var sheet = wk.GetSheetAt(0);

                                for (int j = 1; j <= sheet.LastRowNum; j++)
                                {
                                        IRow row = sheet.GetRow(j);
                                        if (row != null)
                                        {
                                                string province = row.GetCell(1).ToString();
                                                if (!provinces.ContainsKey(province))
                                                {
                                                        provinces.Add(province, new List<string>());
                                                }

                                                string city = row.GetCell(2).ToString();
                                                if (city == "省直辖行政单位")
                                                {
                                                        city = row.GetCell(3).ToString();
                                                }
                                                if (!provinces[province].Contains(city))
                                                {
                                                        provinces[province].Add(city);
                                                }
                                        }
                                }

                        }

                        foreach (var province in provinces.Keys)
                        {
                                System.Console.WriteLine(province);

                                Province p = Province.CreateProvince(province);
                                p.Insert();

                                foreach (var city in provinces[province])
                                {
                                        System.Console.WriteLine("              " + city);

                                        City c = p.CreateCity(city);
                                        c.Insert();
                                }
                        }



                        Console.ReadKey();
                }
        }
}
